package LogicTest;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import Logic.CustomerLogic.CustomerLogic;
import Logic.CustomerLogic.CustomerLogicInterface;
import Po.BookPO;
import Po.Message;
import Po.Order;
import Po.RegisterCustomer;
import Po.Result;
import Po.SimpleBook;
import Po.SimpleCustomer;
import Po.Type;
import VO.SaleBookList;

public class CustomerLogicTest {

	CustomerLogicInterface t;

	@Before
	public void setUp() throws Exception {
		t = CustomerLogic.getCustomerLogic();
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public final void testLogin() {
		SimpleCustomer s = t.login("WHK", "WHK");
		Assert.assertTrue(s.name.equals("WHK"));
		Assert.assertTrue(s.password.equals("WHK"));
	}

	@Test
	public final void testRegiste() {
		Message m = t.registe(new RegisterCustomer("", "", "", "", ""));
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testSearchBook() {
		ArrayList<SimpleBook> list = t.searchBook("Java", Type.name);
		Assert.assertTrue(list.size() == 1);
		Assert.assertTrue(list.get(0).name.equals("Java"));
	}

	@Test
	public final void testAddToShopList() {
		t.searchBook("Java", Type.name);
		Message m = t.addToShopList("222");
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testStartToBuy() {
		t.searchBook("Java", Type.name);
		t.addToShopList("222");
		SaleBookList l = t.startToBuy();
		Assert.assertTrue(l.bookList.size() == 1);
		Assert.assertTrue(l.bookList.get(0).iSBN.equals("222"));
		Assert.assertTrue(l.totalPrice == 10);
	}

	@Test
	public final void testBuy() {
		t.searchBook("Java", Type.name);
		t.addToShopList("222");
		t.startToBuy();
		Message m = t.buy(new SimpleCustomer());
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testGetDetail() {
		t.searchBook("Java", Type.name);
		BookPO b = t.getDetail("222");
		Assert.assertTrue(b.author.equals("WHK"));
		Assert.assertTrue(b.description.equals(""));
	}

	@Test
	public final void testCollectBook() {
		Message m = t.collectBook("");
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testCancle() {
		Message m = t.cancle();
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testDelFromShopList() {
		Message m = t.delFromShopList("");
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testSetNum() {
		t.searchBook("Java", Type.name);
		t.addToShopList("222");
		Message m = t.setNum("222", 0);
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testUsePromotion() {
		Message m = t.usePromotion(1);
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testUseCredits() {
		Message m = t.useCredits(0);
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testDelOneself() {
		Message m = t.delOneself("555");
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testGetCollectedBook() {
		ArrayList<SimpleBook> list = t.getCollectedBook();
		Assert.assertTrue(list.size() == 1);
		Assert.assertTrue(list.get(0).author.equals(""));
	}

	@Test
	public final void testDelFromCollection() {
		Message m = t.delFromCollection("");
		Assert.assertTrue(m.reason.equals(""));
		Assert.assertTrue(m.result == Result.Success);
	}

	@Test
	public final void testGetOrder() {
		ArrayList<Order> list = t.getOrder();
		Assert.assertTrue(list.size() == 1);
		Assert.assertTrue(list.get(0).totalPrice == 0);
	}

}
